package com.lx.test;

//将十进制数转换为二进制
public class tobinaryString {
    public static void main(String[] args) {
        String str = tobinary(6);
        System.out.println(str);
    }

    private static String tobinary(int i) {
        StringBuilder sb = new StringBuilder();

        while(true)
        {
            if(i==0)
            {
                break;
            }
            int num =  i%2;
            i = i/2;
            sb.insert(0,num);
        }
        return sb.toString();
    }
}
